package com.bynk.bynk_demo.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bynk.bynk_demo.model.BookType;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface TypeMapper extends BaseMapper<BookType> {


    @Select("select * from book_type")
    @Results({
            @Result(column = "type_id", property = "typeId"),
            @Result(column = "type_name", property = "typeName"),
            @Result(column = "type_id",property = "books",javaType = List.class, many = @Many(select = "com.bynk.bynk_demo.dao.BookMapper.getBookNamesByTypeId")
            )
    })
    public List<BookType> getTypeAndBook();

    @Select("select * from book_type where type_id=#{id}")
    @Results({
            @Result(column = "type_id", property = "typeId"),
            @Result(column = "type_name", property = "typeName"),
            @Result(column = "type_id",property = "books",javaType = List.class,
            many = @Many(select = "com.bynk.bynk_demo.dao.BookMapper.getBookNamesByTypeId")
            )
    })
    public BookType getTypeAndBookById(Integer id);

    @Select("select type_name from type where type_id=#{typeId}")
    public String getNameById(Integer typeId);
}

